﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DataStyle - shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ */
.hidden { /* 
   display:none;
 */
	
}
/* ]]> */
</style>
<script type="text/javascript">
 /*<![CDATA[*/
if (navigator.appName == "Microsoft Internet Explorer")
{
  //最大化窗口
  self.moveTo(-5,  -5)
  self.resizeTo(screen.availWidth + 8, screen.availHeight + 8)
  //这个脚本定义的宽度其实比原窗口还要大那么一点.
}
 /*]]*/
</script>
 
</head>
<body>
<form id="MainForm">
<div id="Set0">
<p>JSON 格式化    输入:<br />
<textarea cols="90%" rows="5" id="InputTxa">{"is_reference":"1","start_from_city":"\u5317\u4eac \u4e0a\u6d77","line_title":"xxxxxx","tour_type":"1","line_tag":"","go_traffic":"","back_traffic":"","travel_day":"2","travel_day_night":"2","group_people_min":"10","group_people_max":"30","go_off_day":"2009-01-14","day_type":"1","monetary_item":"1","monetary_unit":"1","go_off_city":["1","2"],"city":{"1":{"price_title":["\u6210\u4eba\u4ef7"],"sale_price":["1000"],"discount_price":["900"],"travel_confrere_price":["800"],"line_price":["850"]},"2":{"price_title":["\u6210\u4eba\u4ef7"],"sale_price":["1000"],"discount_price":["900"],"travel_confrere_price":["800"],"line_price":["850"]}},"is_show_subsist_price":"1","subsist_price":"20","not_pay_valid_time":"\u8bf7\u9009\u62e9\u6709\u6548\u65f6\u95f4","confrere_contact":["","",""],"confrere_contact_call":"301","guest_contact":["","",""],"guest_contact_call":"301","draft_id":"25","draft_type":"1","draft_title":"xxxxxx","is_word":"0","travel_type":"0","price_contain":"\u4ef7\u683c\u5305\u542b","price_not_contain":"\u4ef7\u683c\u4e0d\u5305\u542b","special_explain":"\u7279\u522b\u8bf4\u660e","visa_explain":"\u7b7e\u8bc1\u9700\u77e5","travel_explain":"\u65c5\u884c\u5c0f\u8d34\u58eb","travel_info":["\u8bf7\u586b\u5199\u5185\u5bb9"],"travel_pass_city":["\u5317\u4eac"],"travel_pass_landscape":["\u4e0a\u6d77"]}</textarea>
</p>
</div>
<div id="Set1">
<p><input type="submit" id="Submiter" value="Generator" /> <input type="submit" id="UnSubmiter" value="Degenerator" /> <input type="reset" value="Reset" /></p>
</div>
<div id="Set2">
<p class="hidden">分割符: <input type="text" size="5" id="SplitTbx" value="|" /> | <input type="checkbox" value="checkbox" id="SmallToLargeCbx" checked="checked" /> :从长到短</p>
<p class="hidden">默认空白: <input type="text" id="DefaultSpaceTbx" value="1" style="width: 24px;" /> <select id="SpaceSle">
	<option value=" ">Space</option>
	<option value="	">Tab</option>
</select> | <input type="checkbox" value="checkbox" id="TrimTbx" /> :Trim | <input type="checkbox" value="checkbox" id="DebugCbx" /> : Debug</p>
</div>
<div id="Set3">
<p>输出:<br />
<textarea cols="90%" rows="20" id="OutputTxa"></textarea></p>
</div>
<div id="Set4"></div>
<div id="Set5"></div>
<div id="Set6"></div>
</form>
<script type="text/javascript">
 /*<![CDATA[*/
var Set = [];
var SetLen = 7;

for(var i = 0; i < SetLen; i++ ) Set.push(document.getElementById("Set" + i));
var SetOrder = [0, 1, 2, 3, 4, 5, 6];
var Parent = Set[0].parentNode;
for(var i = 0; i < SetLen; i++ ) Parent.removeChild(Set[i]);
for(var i = 0; i < SetLen; i++ ) Parent.appendChild(Set[SetOrder[i]]);

var InputTxa = document.getElementById("InputTxa");
var Submiter = document.getElementById("Submiter");
var UnSubmiter = document.getElementById("UnSubmiter");
var OutputTxa = document.getElementById("OutputTxa");
var DefaultSpaceTbx = document.getElementById("DefaultSpaceTbx");
var SpaceSle = document.getElementById("SpaceSle");
var TrimTbx = document.getElementById("TrimTbx");

UnSubmiter.onclick =
 function()
 {
   var a_ = [OutputTxa.value];
   InputTxa.value = a_;
   return false;
 }
 
Submiter.onclick =
 function()
 {
	 var json_o = eval('('+InputTxa.value+')');
	 var result_s = data_set_to_string_f( json_o );
	 
   OutputTxa.value = result_s;
   return false;
 };
 
/*  
    版本: 2008-9-27 23:23:42
    作用: 把 array 或者 object 格式化输出
必填参数: data_a
*/
function data_set_to_string_f(data_a, level_i)
{/* shawl.qiu, return string, func: is_array_f, is_object_f */
  level_i = level_i || 0;  
  
  var result_a                  = [];
  var item_a                    = [];
  
  var item_count_i              = 0;
  var level_great_zero_b        = (level_i>0);
  
  var sub_pad_s                 = new Array( level_i*2+3 ).join(' ');
  var right_square_bracket_pad  = new Array( level_i*2+1 ).join(' ');
  var left_bracket_s            = '[';
  var right_bracket_s           = ']';  
  var is_object_b               = false;
  
  if( is_object_f( data_a ) )
  {
    left_bracket_s  = '{';
    right_bracket_s = '}';   
    is_object_b     = true;
  }

  if(level_great_zero_b)
  {
    result_a.push(left_bracket_s+'\n');
    right_square_bracket_pad = new Array( level_i*2+1 ).join(' '); ;
  }
  else
  {
    result_a.push(left_bracket_s+'\n');
  }
  
  for(var i in data_a)
  {
    var item_ = data_a[i];   
   
    if( is_array_f(item_) || is_object_f(item_) )
    {
      item_a.push( arguments.callee( item_, level_i+2 ) );
    }
    else
    {
      switch(typeof item_)
      {        
        case 'string'   : item_ = '"'+item_.replace(/\"/g, '\\"')+'"'; break;
        case 'undefined': item_ = 'undefined'; break;
        case 'function' : item_ = item_.toString(); break;
        case 'number'   : break;
        case 'object'   :
          if(item_===null)
          {
            item_ = 'null';
          }
         break;
      }
      
      if(is_object_b)
      {
        item_ = '"'+i+'": '+item_;
      }
   
      if(item_count_i===0)
      {
        if(level_great_zero_b)
        {
          item_a.push( sub_pad_s+''+item_ );
        }
        else
        {
          item_a.push( sub_pad_s+item_ );
        }        
      }
      else
      {
        item_a.push( item_ );
      }      
    }/* if( is_array_f(item_) || is_object_f(item_) ) / else */
   
    item_count_i++;
  }/* for(var i in data_a) */
  
  if(level_great_zero_b)
  {
    result_a.push( item_a.join( '\n'+sub_pad_s+', ' ) );
  }
  else
  {
    result_a.push( item_a.join( '\n'+sub_pad_s+', ' ) );
  }
  
  result_a.push('\n'+right_square_bracket_pad+right_bracket_s);
  
  if(level_great_zero_b){ return result_a.join(''); }  
  return result_a.join('')+';';
}/* function data_set_to_string_f(data_a) */

function is_array_f(input_)
{
  if(input_){ if(input_.constructor==Array){ return true; }; }  
  return false;
}/* function is_array_f(input_a) */

function is_object_f(input_)
{
  if(input_){ if(input_.constructor==Object){ return true; }; }  
  return false;
}/* function is_array_f(input_a) */

 /*]]*/
</script>
</body>
</html>
